package com.wenwei.utils;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.Locale;

/**
 * Created by Administrator on 2017/6/8.
 */
public class RogerDateUtils {

    private static SimpleDateFormat sf = null;

    public static String getDaoJIShi(long time){
        String s = "";
        int hour = (int) time/3600;
        int minute = (int) (time-hour*3600)/60;
        int second = (int) (time-hour*3600-minute*60);
        String s1 = minute+"";
        String s3 = second+"";
        if(s1.length()<2){
            s1 = "0"+s1;
        }
        if(s3.length()<2){
            s3 = "0"+s3;
        }
        return hour+":"+s1+":"+s3;
    }

    public static String getDaoJIShiHome(long time){
        String s = "";
        int hour = (int) time/3600;
        int minute = (int) (time-hour*3600)/60;
        int second = (int) (time-hour*3600-minute*60);
        String s1 = minute+"";
        String s3 = second+"";
        return hour+","+s1+","+s;
    }

    public static long getCurrentTime(){
        return new Date().getTime();
    }

    public static String getDateFormatTag(long time ,String tag){
        Date d= new Date(time);
        sf = new SimpleDateFormat(tag, Locale.getDefault());
        String s = sf.format(d);
        return sf.format(d);
    }

    /**
     * 时间戳转为未字符串
     */
    public static String getDateToString(long time) {
        Date d= new Date(time);
        sf = new SimpleDateFormat("yyyy-MM-dd", Locale.getDefault());
        return sf.format(d);
    }

    public static String getDateToHis(long time) {
        Date d= new Date(time);
        sf = new SimpleDateFormat("MM-dd HH:mm", Locale.getDefault());
        return sf.format(d);
    }

    public static String getDateToStringForMatch(long time) {
        Date d= new Date(time);
        sf = new SimpleDateFormat("MM月dd日", Locale.getDefault());
        return sf.format(d);
    }

    public static String getDateToLongString(long time) {
        Date d= new Date(time);
        sf = new SimpleDateFormat("yyyy-MM-dd HH:mm",Locale.getDefault());
        return sf.format(d);
    }

    /**
     * 获取当前月份
     */
    public static String getCurrentMonth() {
        Date d = new Date();
        sf = new SimpleDateFormat("MM",Locale.getDefault());
        return sf.format(d);
    }

    /**
     * 获取当前时间
     */
    public static String getCurrentHMS() {
        Date d = new Date();
        sf = new SimpleDateFormat("HH:mm:ss",Locale.getDefault());
        return sf.format(d);
    }

    /**
     * 获取当前小时
     */
    public static String getCurrentHour() {
        Date d = new Date();
        sf = new SimpleDateFormat("HH",Locale.getDefault());
        return sf.format(d);
    }

    /**
     * 获取当前分钟
     */
    public static String getCurrentMinus() {
        Date d = new Date();
        sf = new SimpleDateFormat("mm",Locale.getDefault());
        return sf.format(d);
    }


    /**
     * 获取当前年月日
     */
    public static String getCurrentDay(){
        Date date=new Date();//取时间
        Calendar calendar= new GregorianCalendar();
        calendar.setTime(date);
        calendar.add(calendar.DATE, 0);
        date=calendar.getTime(); //这个时间就是日期往后推一天的结果
        SimpleDateFormat formatter =new SimpleDateFormat("yyyy-MM-dd");
        String dateString =formatter.format(date);
        return dateString;
    }

    public static String dateToTimeCuo(String s){
        try{
            SimpleDateFormat format =  new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            Date date = format.parse(s);
            return String.valueOf(date.getTime());
        }catch(Exception e){
            return "";
        }
    }
}
